<!DOCTYPE html >
<!--suppress ALL-->
<html long="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>永和大王门店管理系统</title>
</head>
<body style="padding: 20px;">

<div style="padding: 5px;">
    <h1>用户注册</h1>
</div>
<form>
    <input type="text" name="username" id="username" placeholder="请输入账号">
    <br>
    <input type="password" name="password" id="password" placeholder="请输入密码">
    <br>
    <input type="button" value="注册" id="btn">
    <span id="sp"></span>
</form>
</body>
<script src="/js/jquery.min.js"></script>
<script>
 //当点击注册按钮的时候，使用ajax请求，将用户名和密码提交到Controller当中
 // Controller中有一个变量flag，
 //如果flag==1，注册成功，否则注册失败
$("#btn").click(function (){
    var username=$("#username").val();
    var password=$("#password").val();
    var url="/register";
    var param={"username":username,"password":password};
    //$.get(请求路径，请求参数，回调函数，服务端数据的返回类型)
    $.get(url,param,function (flag){
        if(flag.state==201){
            $("#sp").html(flag.message);
            $("#sp").attr("style","color:red");
        }
        if(flag.state==202){
            $("#sp").html(flag.message);
            $("#sp").attr("style","color:red");
        }
        if(flag.state==203){
            $("#sp").html(flag.message);
            $("#sp").attr("style","color:red");
        }
        if(flag.state==204){
            $("#sp").html(flag.message);
            $("#sp").attr("style","color:red");
        }
        if(flag.state==200){
            $("#sp").html(flag.message);
            $("#sp").attr("style","color:green");
        }

    });

});

</script>
</html>

